package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.anno.AutoFillAnnotation;
import com.sky.entity.Dish;
import com.sky.entity.SetmealDish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    @AutoFillAnnotation(OperationType.INSERT)
    void insertDish(Dish dish);


    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> selectByCategoryId(Long categoryId);

    /**分页查询*/
    Page<DishVO> selectByPage(Integer categoryId, String name, Integer status);

    /**查询要删除的菜品的状态*/
    List<Integer> selectByIdsInDish(List ids);
/**查询要删除的菜品的关联状态*/
    List<SetmealDish> selectByIdsInS_D(List ids);
/**删除菜品*/
    void deleteDishByIds(List ids);
/**跟新菜品数据*/
@AutoFillAnnotation(OperationType.UPDATE)
    void updateDish(Dish dish);

    /**修改启售/禁售状态*/
@Update("update dish set status=#{status} where id = #{id}")
    void updateStatus(Integer status,Long id);

/**根据id查询*/
    DishVO selectById(Long id);


    @Select("select * from dish where category_id = #{categoryId} and status = #{status}")
    List<Dish> list(Long categoryId, Integer status);


    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
